﻿using BLL;
using DAL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;

namespace HotelCode.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ShopController : ControllerBase
    {
        public ShopBLL ShopBLL { get; }

        public ShopController(ShopBLL shopBLL)
        {
            ShopBLL = shopBLL;
        }
        [HttpPost]
        /// <summary>
        /// 添加门店
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public IActionResult ShopAdd(ShopModel info)
        {
            try
            {
                int res= ShopBLL.ShopAdd(info);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpDelete]
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IActionResult ShopDelete(int id)
        {
            try
            {
                int res=ShopBLL.ShopDelete(id);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpDelete]
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IActionResult ShopDeleteAll(string ids)
        {
            try
            {
                int res = ShopBLL.ShopDeleteAll(ids);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpPut]
        /// <summary>
        /// 批量修改状态
        /// </summary>
        /// <param name="ids"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public IActionResult ShopUpdateAll(string ids, int state)
        {
            try
            {
                int res = ShopBLL.ShopUpdateAll(ids, state);
                return Ok(res);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpGet]
        /// <summary>
        /// id查询(反填)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IActionResult GetShopId(int id)
        {
            try
            {
               var list=ShopBLL.GetShopId(id);
                return Ok(list);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpPut]
        /// <summary>
        /// 修改门店信息
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public IActionResult ShopUpdate(ShopModel info)
        {
            try
            {
                var list = ShopBLL.ShopUpdate(info);
                return Ok(list);
            }
            catch (Exception)
            {

                throw;
            }
        }
        [HttpGet]
        /// <summary>
        /// 显示查询分页
        /// </summary>
        /// <param name="totalCount"></param>
        /// <param name="totalPage"></param>
        /// <param name="pageindex"></param>
        /// <param name="pageSize"></param>
        /// <param name="ShopName"></param>
        /// <param name="Scope"></param>
        /// <returns></returns>
        public IActionResult GetShopList( int pageindex = 1, int pageSize = 2, string? ShopName = "", int? Scope = null)
        {
            try
            {
                 int totalCount = 0;
                 int totalPage = 0;
                var list=ShopBLL.GetShopList(out totalCount, out totalPage, pageindex, pageSize, ShopName,Scope);
                return Ok(new { 
                    list=list,
                    totalCount=totalCount,
                    totalPage=totalPage
                });

            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
